#include <cstdio>
#include <cstdlib>
#include <dlfcn.h>

int main() {
	void *handle;
	void (*hello)(void);
	char *error;

	handle = dlopen("./dynamic.so", RTLD_LAZY);
	if(handle == NULL) {
		fprintf(stderr, "Error: open/load error of dynamic.so failed: %s\n", dlerror());
		exit(1);
	}

	hello = (void(*)(void)) dlsym(handle, "hello");
	if((error = dlerror()) != NULL) {
		fprintf(stderr, "Error: symbol lookup in dynamic.so failed: %s\n", dlerror());
		exit(2);
	}

	hello();

	dlclose(handle);

	return 0;
}
